/**
 * Copyright (C) 2017 PatSnap Pte Ltd, All Rights Reserved.
 */
package com.job.service;


import com.job.bean.Comment;
import com.job.dao.CommentRepository;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Author: Tory
 * Date: 4/8/17
 * Time: 7:38 PM
 */
@Service
public class CommentService {

    @Autowired
    private CommentRepository commentRepository;

    public void save(Comment comment) {
        commentRepository.save(comment);
    }

    public List<Comment> findAll() {
        List<Comment> commentList = new ArrayList<>();
        Iterable<Comment> commentIterable = commentRepository.findAll();
        if (null != commentIterable) {
            commentIterable.forEach(commentList::add);
        }
        return commentList;
    }


    public void delete(Integer id){
        commentRepository.delete(id);
    }

    public List<Comment> findCommentByGoodId(Integer goodId) {
        return commentRepository.findCommentByGoodId(goodId);
    }
}
